﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ZhiJiao.Service.Abstracts;
using ZhiJiao.Service.Dto;
using ZhiJiao.Service.FilterDto;

namespace ZHIJIAO.Controllers
{
    public class InstructionController : Controller
    {
        private readonly IInstructionService _insService;

        public InstructionController(IInstructionService insService)
        {
            _insService=insService;
        }

        [Authorize]
        public IActionResult Index()
        {
            return View();
        }




        [HttpPost("api/instruction/add-submit")]
        public IActionResult AddSubmit([FromBody]AddInstructionDto model) 
        {
            return Json(_insService.AddSubmit(model));
        }

        [HttpPost("api/instruction/edit-submit")]
        public IActionResult EditSubmit([FromBody] AddInstructionDto model)
        {
            return Json(_insService.EditSubmit(model));
        }

        [HttpGet("api/instruction/delete")]
        public IActionResult Delete(long id)
        {
            return Json(_insService.Delete(id));
        }

        [HttpGet("api/instruction/get-list")]
        public IActionResult GetList( bool? isActive,string? instructionName)
        {
            var filter = new InsFilter { IsActive = isActive, InstructionName = instructionName };
            return Json(_insService.GetList(filter));
        }

    }
}
